from core import *


class TraceTreeModel(TreeModel):
    def __init__(self, root):
        TreeModel.__init__(self)
        self.append_column("Function", str, self.getcol_function)
        self.append_column("Location", str, self.getcol_location)
        self.append_column("Arguments", str, self.getcol_args)
        self.root = root
    
    def getcol_function(self, path):
        #print "getting", path
        return "hello"
    def getcol_location(self, path):
        return "world"
    def getcol_args(self, path):
        return "(1,2,3,4)"
    def get_number_of_children(self, path):
        return 3

class TraceTreeView(gtk.TreeView):
    def __init__(self, model):
        gtk.TreeView.__init__(self, model)
        self.model = model
        for colobj, type, getter in self.model.columns:
            self.append_column(colobj)
    
    def ui_collapse(self, path = None):
        if path is None:
            path, column = self.get_cursor()
        if self.row_expanded(path):
            self.collapse_row(path)
        elif len(path) >= 2:
            self.set_cursor(path[:-1])
    
    def ui_expand(self, path = None):
        if path is None:
            path, column = self.get_cursor()
        if not self.model.iter_has_child(self.model.get_iter(path)):
            return
        self.expand_row(path, False)
        self.set_cursor(path + (0,)) 

tv = TraceTreeView(TraceTreeModel(None))
tv.set_enable_search(False)
tv.set_enable_tree_lines(True)
#tv.set_fixed_height_mode(True)
tv.set_rules_hint(True)
tv.show()
def f(tv, path, *args):
    tv.ui_expand(path)
    #print "row-activated", args
    return True
tv.connect("row-activated", f)


doc = Window("HPTrace Reader",
    HBox(
        Frame("Source code",
            VBox(
                Label("Filename"),
                Scrolled(tv),
            )
        ),
        VBox(
            Frame("Bookmarks",
                VBox(
                    Label("nothing yet"),
                    Button("floop"),
                )
            ),
            Frame("Filters",
                VBox(
                    Label("nothing yet as well"),
                    Button("bloop"),
                )
            ),
            Frame("Search",
                VBox(
                    Label("nothing yet too"),
                    Button("zloop"),
                )
            ),
        )
    ),
    menu = MenuBar(
        Menu("_File",
            MenuItem("_Load"),
            MenuItem("_Unload"),
            Menu("Sex",
                MenuItem("kinki"),
                MenuItem("bdsm"),
            ),
            MenuSep(),
            MenuItem("E_xit"),
        ),
        Menu("_Filter",
            MenuItem("_Load"),
            MenuItem("_Unload"),
        ),
        Menu("_Help",
           MenuItem("_About"), 
        ),
    ),
    accel = None,
)


if __name__ == "__main__":
    doc.show()
    gtk.main()